/**
 * Generali Solutions d'assurances - Tous droits rï¿½servï¿½s &copy; 2007 - 2010
 */
package fr.generali.accueilclient.referentiel.services.impl;

import java.util.HashMap;
import java.util.Map;

import javax.xml.ws.WebServiceException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import fr.generali.accueilclient.commun.exception.AccueilClientBusinessException;
import fr.generali.accueilclient.commun.exception.AccueilClientTechnicalException;
import fr.generali.accueilclient.referentiel.ReferentielEnum;
import fr.generali.accueilclient.referentiel.services.IReferentielClientService;
import fr.generali.refservcommuns.rce.demat.referentiel.client.services.IConsultationListParamRceClientWebService;
import fr.generali.refservcommuns.rce.demat.referentiel.client.list.param.DossierParamClient;
import fr.generali.refservcommuns.rce.demat.referentiel.client.services.WsRceBusinessException;
import fr.generali.refservcommuns.rce.demat.referentiel.client.services.TechnicalFault;

/**
 * @author Holmes Kelly
 */
@Service("referentielClientService")
public class ReferentielClientService implements IReferentielClientService {

    /**
     * LOGGER
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(ReferentielClientService.class);

    /**
     * Service de rï¿½fï¿½rentiel client RCE
     */
    @Autowired
    @Qualifier("T3")
    private IConsultationListParamRceClientWebService listeParamsService;

    /**
     * Classe permettant de mapper les rï¿½sultats des appels aux webservices
     */
    @Autowired
    private ReferentielServiceMapper referentielServiceMapper;

    /**
     * {@inheritDoc}
     */
    public Map<ReferentielEnum, Map<String, String>> chargerReferentielClient() throws AccueilClientBusinessException {
        Map<ReferentielEnum, Map<String, String>> mapperReferentielClient =
                        new HashMap<ReferentielEnum, Map<String, String>>(0);

        try {
            DossierParamClient dossier = listeParamsService.consulterListParamClient();
            mapperReferentielClient = referentielServiceMapper.mapperReferentielClient(dossier);
        } catch (WsRceBusinessException e) {
            LOGGER.error("Erreur business lors du chargement du referentiel client RCE: '{}'.", e.getMessage());
            throw new AccueilClientBusinessException(e.getMessage(), e);
        } catch (TechnicalFault e) {
            LOGGER.error("Erreur technique lors du chargement du referentiel client RCE: '{}'.", e.getMessage());
            throw new AccueilClientBusinessException(e.getMessage(), e);
        } catch (WebServiceException ex) {
            LOGGER.error("Referentiel RCE non disponible", ex.getMessage());
            throw new AccueilClientTechnicalException(ex.getMessage(), ex);
        }

        return mapperReferentielClient;
    }
}
